/*
 * Copyright (c) 2014 pkzd/1.0, 颜文泽(robin)
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     1 Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     2 Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include	<asm.h>
#include	<idt.h>
#include	<map.h>
#include	<pic.h>
#include	<buf.h>
#include	<tty.h>
#include	<ide.h>
#include	<sig.h>
#include	<prf.h>
#include	<page.h>
#include	<proc.h>
#include	<mount.h>
#include	<string.h>

int
main(void)
{
	minit();
	pic_init();
	cinit();
	binit();
	page_list_init();
	idt_init();
	clk_init();
	ide_init();
	proc_init();
	cnsopen(MAKEDEV(0, 0), 0);
	pic_eblirq(KBD_IRQ);
	time_init();
	sti();
	if(!fork()){
		char *argv[] = { "/init", NULL };
		iinit();
		setpgid();
		up->p_signal[SIGFPE] = SIG_DFL;
		up->p_signal[SIGBUS] = SIG_DFL;
		open("/dev/tty", O_RDONLY, 0);
        	open("/dev/tty", O_WRONLY, 0);
        	open("/dev/tty", O_WRONLY, 0);
		printf("Error: exec init fault\n", execve(argv[0], argv, NULL));
		exit(1);
	}
	sched();
}
